package com.example.im.ui.fragment

import android.content.Context
import android.os.Bundle
import android.text.Editable
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import com.example.im.R
import com.example.im.bean.UserRoom
import com.example.im.callback.OnClickUserListener
import com.example.im.mvp.base.BasePresenter
import com.example.im.ui.abstracts.AbstractBaseFragment
import com.example.im.common.Constants
import kotlinx.android.synthetic.main.fragment_user_add_to.*

class UserAddToFragment : AbstractBaseFragment<BasePresenter<*>>(), View.OnClickListener {

    private var userRoom: UserRoom? = null

    private var mOnClickUserListener: OnClickUserListener? = null

    companion object {
        fun newInstance(userRoom: UserRoom): UserAddToFragment {
            val bundle = Bundle()
            bundle.putSerializable(Constants.BUNDLE_T0_USER_ROOM_DATA, userRoom)
            val fragment = UserAddToFragment()
            fragment.arguments = bundle
            return fragment
        }
    }


    override fun onAttach(context: Context) {
        super.onAttach(context)
        mOnClickUserListener = context as OnClickUserListener
    }

    override val layoutId: Int
        get() = R.layout.fragment_user_add_to

    override fun initView() {

        userRoom = arguments!!.getSerializable(Constants.BUNDLE_T0_USER_ROOM_DATA)
                as UserRoom

        tv_user_nick_name.text = userRoom!!.nickname
        tv_user_name.text = userRoom!!.account
        ed_user_again.text = Editable.Factory.getInstance()
            .newEditable(userRoom!!.nickname)

        tv_add_to_send.setOnClickListener(this)
    }

    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
        activity!!.menuInflater.inflate(R.menu.top_nav_menu_send, menu)
        super.onCreateOptionsMenu(menu, inflater)
    }

    override fun initPresenter() {

    }

    override fun initLazyLoad() {

    }

    override fun onClick(v: View?) {
        mOnClickUserListener!!.onClickAddTo(v!!, userRoom!!)
    }

}